'use strict';

const Service = require('egg').Service;

class UsersService extends Service {
  // 分页查询
  async findAndCountAll(opt) {
    const { page, page_size } = opt;
    const { count, rows } = await this.ctx.model.Users.findAndCountAll({
      limit: page_size,
      offset: (page - 1) * page_size,
    });
    return {
      current_page: parseInt(page),
      page_size: parseInt(page_size),
      total: count,
      data: rows,
    };
  }

  async findOne(options) {
    const { Users } = this.ctx.model;
    return await Users.findOne(options);
  }

  async create(options) {
    const { Users } = this.ctx.model;
    return await Users.create(options);
  }
}

module.exports = UsersService;
